package cn.hqc.basic.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

public class SendEmailUtil {

//    // 注入邮件对象
//    @Autowired
//    private JavaMailSender javaMailSender;

    public static void sendEmail(Long shopId){
        try {
            ApplicationContext context = SpringBeanUtil.getContext();
            JavaMailSender javaMailSender = context.getBean(JavaMailSender.class);
            // 发送邮件
            // 1.创建复杂邮件对象
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            // 2.发送复杂邮件的工具类
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom("1754165180@qq.com");
            helper.setSubject("宠物乐园审核结果通知");
            // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
            helper.setText("<h1>恭喜您，通过审核，请点击下方链接激活店铺：</h1> " +
                    "http://localhost:8080/shop/activity/"+shopId,true);

            // 5.设置收件人
            helper.setTo("1754165180@qq.com");
            // 6.发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }

    }

}
